//
//  GPSTrainingSpeedRangeType.swift
//  DaRings
//
//  Created by 尹琼 on 2023/2/2.
//

import UIKit

public enum GPSTrainingSpeedRangeType: CaseIterable {
    
    /// 未知
    case unkown
    
    /// 轻松跑
    case easyRun
    
    /// 马拉松
    case marathon
    
    /// 乳酸阀值
    case lacticAcid
    
    /// 无氧耐力
     case anaerobic
    
    /// 高强度间歇跑
    case intervalRun
    
    
    public var paceRange: Range<Double> {
        
        switch self {
        case .easyRun:
            return 7.00 ..< Double.greatestFiniteMagnitude
        case .marathon:
            return 6.30 ..< 7.00
        case .lacticAcid:
            return 6.00 ..< 6.30
        case .anaerobic:
            return 5.30 ..< 6.00
        case .intervalRun:
            return 0 ..< 5.30
        case .unkown:
            return Double.leastNormalMagnitude ..< 0
        }
        
    }
    
    public var color: UIColor {
        
        switch self {
        case .unkown:
            return GPSTrainingSpeedRangeType.intervalRun.color
        case .easyRun:
            return UIColor.GPSTraining.easyRun
        case .marathon:
            return UIColor.GPSTraining.marathon
        case .lacticAcid:
            return UIColor.GPSTraining.lacticAcid
        case .anaerobic:
            return UIColor.GPSTraining.anaerobic
        case .intervalRun:
            return UIColor.GPSTraining.intervalRun
        
        }
        
    }
    
   public static var rangeTypes: [GPSTrainingSpeedRangeType] {
       return Self.allCases.filter( {$0 != .unkown } )
    }
    
    public static func rangeType(with speed: Double) ->GPSTrainingSpeedRangeType {
        
     
        var rangeType: GPSTrainingSpeedRangeType = .easyRun
        for type in rangeTypes {
            
            if type.paceRange.contains(speed) {
                rangeType = type
                break
            }
        }
        
        return rangeType
    }

}
